home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / PROGRAMR / UPC12BS1.ZIP / LIB / IMPORT.C < prev    next >
C/C++ Source or Header  |  1993-09-27  |  35KB  |  860 lines

  1. /*--------------------------------------------------------------------*/
  2. /*    i m p o r t . c                                                 */
  3. /*                                                                    */
  4. /*    File name mapping routines for UUPC/extended                    */
  5. /*--------------------------------------------------------------------*/
  6.  
  7. /*--------------------------------------------------------------------*/
  8. /*    Changes Copyright (c) 1989 by Andrew H. Derbyshire.             */
  9. /*                                                                    */
  10. /*    Changes Copyright (c) 1990-1993 by Kendra Electronic            */
  11. /*    Wonderworks.                                                    */
  12. /*                                                                    */
  13. /*    All rights reserved except those explicitly granted by the      */
  14. /*    UUPC/extended license agreement.                                */
  15. /*--------------------------------------------------------------------*/
  16.  
  17. /*
  18.  *    $Id: import.c 1.9 1993/09/27 04:04:06 ahd Exp $
  19.  *
  20.  *    $Log: import.c $
  21.  *     Revision 1.9  1993/09/27  04:04:06  ahd
  22.  *     Correct creation of pointer to file system name
  23.  *
  24.  *     Revision 1.8  1993/09/26  03:32:27  dmwatt
  25.  *     Use Standard Windows NT error message module
  26.  *
  27.  *     Revision 1.7  1993/09/20  04:38:11  ahd
  28.  *     TCP/IP support from Dave Watt
  29.  *     't' protocol support
  30.  *     OS/2 2.x support
  31.  *
  32.  *     Revision 1.6  1993/09/03  12:54:55  ahd
  33.  *     Add missing endif
  34.  *
  35.  *     Revision 1.5  1993/09/03  12:18:55  dmwatt
  36.  *     Windows NT support for long names on file systems
  37.  *
  38.  *     Revision 1.4  1993/09/02  12:08:17  ahd
  39.  *     HPFS Support
  40.  *
  41.  *     Revision 1.3  1993/04/11  00:31:31  dmwatt
  42.  *     Global edits for year, TEXT, etc.
  43.  *
  44.  * Revision 1.2  1992/11/22  21:06:14  ahd
  45.  * Correct mapping of dos paths with trailing slashes
  46.  *
  47.  */
  48.  
  49. /*--------------------------------------------------------------------*/
  50. /*                        System include files                        */
  51. /*--------------------------------------------------------------------*/
  52.  
  53. #include <stdio.h>
  54. #include <ctype.h>
  55. #include <stdlib.h>
  56. #include <string.h>
  57. #include <time.h>
  58.  
  59. #if defined(FAMILYAPI) || defined(__OS2__)
  60. #define INCL_NOPM             // No need to include OS/2 PM info
  61. #define INCL_BASE
  62. #include <os2.h>
  63. #elif defined(WIN32)
  64. #include <windows.h>
  65. #endif
  66.  
  67. /*--------------------------------------------------------------------*/
  68. /*                    UUPC/extended include files                     */
  69. /*--------------------------------------------------------------------*/
  70.  
  71. #include "lib.h"
  72. #include "import.h"
  73. #include "arbmath.h"
  74. #include "hostable.h"
  75. #include "usertabl.h"
  76. #include "security.h"
  77.  
  78. #ifdef WIN32
  79. #include "pnterr.h"
  80. #endif
  81.  
  82. #define MAX_DIGITS 20         /* Number of digits for arb math */
  83.  
  84. /*--------------------------------------------------------------------*/
  85. /*                    Internal function prototypes                    */
  86. /*--------------------------------------------------------------------*/
  87.  
  88. #define min(x,y) (((x) < (y)) ? (x) : (y))
  89.  
  90. currentfile();
  91.  
  92. /*--------------------------------------------------------------------*/
  93. /*                     Local function prototypes                      */
  94. /*--------------------------------------------------------------------*/
  95.  
  96. static void ImportName( char *local,
  97.                         const char *canon,
  98.                         size_t charsetsize,
  99.                         const boolean longname );
  100.  
  101. static boolean advancedFS( const char *path );
  102.  
  103. /*-------------------------------------------------------------------*/
  104. /*                                                                   */
  105. /*   i m p o r t p a t h                                             */
  106. /*                                                                   */
  107. /*   Convert a canonical name to a format the host can handle        */
  108. /*                                                                   */
  109. /*   These routines convert file name between canonical form, which  */
  110. /*   is defined as a 'unix' style pathname, and the MS-DOS all       */
  111. /*   uppercase "xxxxxxxx.xxx" format.                                */
  112. /*                                                                   */
  113. /*   If the canonical name does not have a path, that is the file is */
  114. /*   destined for the local spool directory, we can assume the UNIX  */
  115. /*   name will normally be in a format like this:                    */
  116. /*                                                                   */
  117. /*                                                                   */
  118. /*       X.hostid#######            (Execute files)                  */
  119. /*       C.hostid#######            (Call files)                     */
  120. /*       D.hostid#######            (Data files)                     */
  121. /*                                                                   */
  122. /*   where "hostid" may be most, but not always all, of the local    */
  123. /*   host or remote host (the file came from or is going to) and     */
  124. /*   "######" can be any character valid for the UNIX file system.   */
  125. /*   Note, however, that the routine has to be generic to allow for  */
  126. /*   other file names to be placed in the spool directory without    */
  127. /*   collisions.                                                     */
  128. /*                                                                   */
  129. /*   Avoiding collisions in the spool directory is important; when   */
  130. /*   receiving files with mixed case names longer than 11            */
  131. /*   characters, sooner or later a file name collision will occur.   */
  132. /*                                                                   */
  133. /*   We can also assume that only UUPC will see these names, which   */
  134. /*   means we can transform the name using any method we choose, so  */
  135. /*   long as the UUPC functions opening the file always call         */
  136. /*   importpath, and that importpath is reducible (that is, two      */
  137. /*   calls to importpath with the same argument always yield the     */
  138. /*   same result).  Note that if end user really wanted the file in  */
  139. /*   the spool directory, all he has to do is rename the file-- far  */
  140. /*   better than losing the data because duplicate file names.       */
  141. /*                                                                   */
  142. /*   For these files, we map the name as follows:                    */
  143. /*                                                                   */
  144. /*   0 - If the name is a valid MS-DOS name, use it without changing */
  145. /*                                                                   */
  146. /*   1 - Begin the output name by inserting up to the first eight    */
  147. /*       characters of the remote host name (followed by a slash) as */
  148. /*       a subdirectory name.                                        */
  149. /*                                                                   */
  150. /*   2 - If the input name begins with an uppercase alphabetic       */
  151. /*       character followed by a period, also insert the alphabetic  */
  152. /*       (followed by a slash) to make this a second subdirectory.   */
  153. /*       Then, move the logical start of the input name past the two */
  154. /*       characters.                                                 */
  155. /*                                                                   */
  156. /*   3 - Determine the number of characters the local host and       */
  157. /*       remote hosts have equal to the next characters of the input */
  158. /*       name, up to a maximum of 8, and zero the lower of the two   */
  159. /*       counts.  Then, step past the number of characters of the    */
  160. /*       larger count.                                               */
  161. /*                                                                   */
  162. /*       For example, if the file name is X.keane22222 and the local */
  163. /*       host name is kendra (2 characters match) and the remote     */
  164. /*       host is keane1 (5 characters mat